import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus';
import { resolve } from 'path';

export default defineConfig({
    plugins: [
        vue(),
        vueSetupExtend()
        // Components({
        //     resolvers: [ElementPlusResolver()]
        // })
    ],
    resolve: {
        alias: {
            '@': resolve(__dirname, 'src')
        }
    },
    server: {
        port: 8081,
        proxy: {
            '/mockapi': {
                target: 'https://console-mock.apipost.cn/app/mock/project/a3678e3a-d4e4-40c7-99ef-873b843ab9d9',
                changeOrigin: true,
                rewrite: path => {
                    return path.replace(/^\/mockapi/, '');
                }
            }
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@use "@/assets/scss/element/index.scss" as *;`
            }
        },
        postcss: {
            plugins: [
                {
                    postcssPlugin: 'internal:charset-removal',
                    AtRule: {
                        charset: atRule => {
                            if (atRule.name === 'charset') {
                                atRule.remove();
                            }
                        }
                    }
                }
            ]
        }
    },
    build: {
        sourcemap: true
    }
});
